package apk.yoursms.smslist;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import apk.yoursms.R;
import apk.yoursms.Values;
import apk.yoursms.views.TextView;

public class SmsListAdapter extends ArrayAdapter<String> {

    private Activity activity;
    private ArrayList<String> messages;
    private ArrayList<String> allSites;

    public SmsListAdapter(Activity smsList, int listItem,
	    ArrayList<String> messages, ArrayList<String> allSites) {
	super(smsList, listItem, messages);
	activity = smsList;
	this.messages = messages;
	this.allSites = allSites;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
	if (convertView == null) {
	    LayoutInflater infalInflater = activity.getLayoutInflater();
	    convertView = infalInflater.inflate(R.layout.list_item, null);
	}

	TextView itemSite = (TextView) convertView
		.findViewById(R.id.textItemSite);
	TextView itemText = (TextView) convertView
		.findViewById(R.id.textItemList);

	String site = allSites.get(position);
	itemSite.setText(Values.siteToString.get(site));
	itemText.setText(messages.get(position));

	return convertView;
    }

}
